package com.xhs.config;

import com.mybatisflex.core.audit.AuditMessage;
import com.mybatisflex.core.audit.MessageReporter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @desc: mybatis-Flex 收集的SQL审计日志发送到指定位置
 * @projectName: mybatis-flex-demo
 * @author: xhs
 * @date: 2023-09-13  18:06
 * @version: JDK 1.8
 */
@Slf4j
@Component
public class ConsoleMessageReporter implements MessageReporter {
    @Value("${spring.application.name}")
    private String serviceName;
    @Override
    public void sendMessages(List<AuditMessage> messages) {
        for (AuditMessage message : messages) {
            message.setPlatform(serviceName);
            log.info("\n <==SQL-AUDIT:{}", message.toString());
            // 将SQL发送到指定位置
        }
    }
}
